package simple.charlie.hibernate.controllers;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import simple.charlie.hibernate.book.entities.Book;
import simple.charlie.hibernate.book.services.BookServices;
import simple.charlie.hibernate.student.entities.Student;
import simple.charlie.hibernate.student.services.StudentServices;

@RestController
public class Test {

	@Autowired
	private BookServices bookServices;
	@Autowired
	private StudentServices studentServices;

	@RequestMapping(value = "/save", method = RequestMethod.GET)
	public void save() {

		Book book = new Book();
		book.setName("Thinking In Java");
		Student student = new Student();
		student.setName("Charlie");

		bookServices.save(book);
		studentServices.save(student);

	}

	@RequestMapping(value = "/get", method = RequestMethod.GET)
	public Collection<Object> get() {
		Collection<Object> list = new ArrayList<Object>();
		list.addAll(bookServices.get());
		list.addAll(studentServices.get());
		return list;
	}
}
